<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8" />
  <title>01_天气案例</title>
  <style>
    img {
      width: 100px;
    }
  </style>
  <!-- 引入Vue -->
  <script type="text/javascript" src="../js/vue.js"></script>
</head>

<body>
  <!-- 准备好一个容器-->
  <div id="demo">
    <h2>今天天气很{{isHotCook}}</h2>
    <img :src='url'>
    <button @click="onchangeWether" style="color: cadetblue;">切换天气</button>
  </div>
</body>

<script type="text/javascript">
  new Vue({
    el: '#demo',
    data: {
      isHot: true,
      url: 'http://49.232.112.44/images/hot.jpg'
    },
    methods: {
      onchangeWether() {
        setTimeout(() => {
          this.isHot = !this.isHot
        }, 100)

      }
    },
    computed: {
      isHotCook() {
        return this.isHot ? '炎热' : '凉爽'
      }
    },
    watch: {
      isHot: {
        handler(value) {
          console.log(111);
          // 判断
          if (value) {
            this.url = 'http://49.232.112.44/images/hot.jpg'
          } else {
            this.url = 'http://49.232.112.44/images/cool.jpg'
          }
        }
      }
    }
  })
</script>

</html>